#! usr/bin/env python

import os
import pygame
import random

# This is the Door deck object

class DoorDeck (pygame.sprite.Sprite):
    def __init__ (self):
        pygame.sprite.Sprite.__init__(self)
        self.deck = []
        self.image = pygame.image.load (os.path.join
            ('data/images/Cards/', 'DoorCard.png')).convert_alpha()
        self.image = pygame.transform.scale (self.image, (180, 144))
        self.rect = self.image.get_rect()
        self.mouse_x = 0
        self.mouse_y = 0
        self.mouse_over = False
        self.mouse_click = False
        self.x = 1030
        self.rightx = 1210
        self.y = 10
        self.bottomy = 154
        self.rect.topleft = (self.x, self.y)
        self.master_container = None
        self.clicked_on_deck = False # This tells the main loop if the user has clicked on the deck
        self.sound = pygame.mixer.Sound (os.path.join('data/audio','DoorCreak.wav'))
        self.sound.set_volume (0.45)

    def AddCard (self, card):
        self.deck.append(card) # Add a card to the deck.
        card.SetLocation (3)   # Update the location of the card.
        card.player = 0
        card.x = 0
        card.y = 0

    def DrawCard (self):
        # Remove a card from the deck and send it to calling function
        # Is there any cards left to draw?
        x = self.GetLength()
        if x > 0:
            self.temp = self.deck.pop (random.randint(0, x))
            return self.temp
        else:
            return None

    def GetLength (self):
        self.length = len(self.deck) - 1
        return self.length

    def KnockDownTheDoor (self, player):
        # This function takes the top door card, assigns it to the player
        # who is drawing it, and activates the card. If it is a monster,
        # combat ensues. If it is a trap, the trap hits the player. If
        # it is anything else, it goes to the player hand.
        self.sound.play () # Play the audio of the door creaking

    def PrintData (self):
        print '''\n
Door Deck
Cards Remaining: %d
\n''' % len(self.deck)

    def SetupMasterContainer (self, master_container):
        self.master_container = master_container

    def Update (self, mouse_x, mouse_y, mouse_click):
        self.mouse_x = mouse_x
        self.mouse_y = mouse_y
        self.mouse_click = mouse_click
        self.mouse_over = False

        # Is mouse over draw deck?
        if ((mouse_x > self.x) and (mouse_y > self.y) and
               (mouse_x < self.rightx) and (mouse_y < self.bottomy)):
            self.mouse_over = True
            # Draw sparkles
            s = self.master_container [23]
            s(self.x, self.rightx, self.y, self.bottomy)
            # Mouse is over draw deck
            # Ignore anything that is not a mouse left click
            if mouse_click:
                self.PrintData ()
                self.clicked_on_deck = True

        self.master_container[22].blit (self.image, self.rect)

# This is the Door Discard deck object

class DoorDiscardDeck (pygame.sprite.Sprite):
    def __init__ (self):
        pygame.sprite.Sprite.__init__(self)

        self.deck = []
        self.image = pygame.image.load (os.path.join
            ('data/images/Cards/', 'DoorCard.png')).convert_alpha()
        self.image = pygame.transform.scale (self.image, (180, 144))
        self.rect = self.image.get_rect()
        self.mouse_x = 0
        self.mouse_y = 0
        self.mouse_over = False
        self.mouse_click = False
        self.x = 1030
        self.rightx = 1210
        self.y = 162
        self.bottomy = 306
        self.rect.topleft = (self.x, self.y)
        self.master_container = None
        self.clicked_on_deck = False # This tells the main loop if the user has clicked on the deck

    def AddCard (self, card):
        self.deck.append(card) # Add a card to the deck.
        card.SetLocation (4)   # Update the location of the card.
        card.player = 0
        card.x = 0
        card.y = 0

    def DrawCard (self):
        # Remove a card from the deck and send it to calling function
        # Is there any cards left to draw?
        x = self.GetLength ()
        if x > 0:
            self.temp = self.deck.pop ()
            return self.temp
        else:
            return None

    def GetLength (self):
        self.length = len(self.deck) - 1
        return self.length
    
    def PrintData (self):
        print '''\n
Door Discard Deck
Cards Remaining: %d
\n''' % len(self.deck)
        
    def SetupMasterContainer (self, master_container):
        self.master_container = master_container

    def Update (self, mouse_x, mouse_y, mouse_click):
        self.mouse_x = mouse_x
        self.mouse_y = mouse_y
        self.mouse_click = mouse_click
        self.mouse_over = False

        # Is mouse over draw deck?
        if ((mouse_x > self.x) and (mouse_y > self.y) and
               (mouse_x < self.rightx) and (mouse_y < self.bottomy)):
            self.mouse_over = True
            # Draw sparkles
            s = self.master_container [23]
            s(self.x, self.rightx, self.y, self.bottomy)
            # Mouse is over draw deck
            # Ignore anything that is not a mouse left click
            if mouse_click:
                self.PrintData ()
                self.clicked_on_deck = True

        self.master_container[22].blit (self.image, self.rect)

# This is the treasure deck object

class TreasureDeck (pygame.sprite.Sprite):
    def __init__ (self):
        pygame.sprite.Sprite.__init__(self)

        self.deck = []
        self.image = pygame.image.load (os.path.join
            ('data/images/Cards/', 'TreasureCard.png')).convert_alpha()
        self.image = pygame.transform.scale (self.image, (180, 144))
        self.rect = self.image.get_rect()
        self.mouse_x = 0
        self.mouse_y = 0
        self.mouse_over = False
        self.mouse_click = False
        self.x = 1030
        self.rightx = 1210
        self.y = 322
        self.bottomy = 466
        self.rect.topleft = (self.x, self.y)
        self.master_container = None
        self.clicked_on_deck = False # This tells the main loop if the user has clicked on the deck

    def AddCard (self, card):
        self.deck.append(card) # Add a card to the deck.
        card.SetLocation (3)   # Update the location of the card.
        card.player = 0
        card.x = 0
        card.y = 0

    def DrawCard (self):
        # Remove a card from the deck and send it to calling function
        # Is there any cards left to draw?
        x = self.GetLength()
        if x > 0:
            self.temp = self.deck.pop (random.randint(0, x))
            return self.temp
        else:
            return None

    def GetLength (self):
        self.length = len(self.deck) - 1
        return self.length

    def PrintData (self):
        print '''\n
Treasure Deck
Cards Remaining: %d
\n''' % len(self.deck)
        
    def SetupMasterContainer (self, master_container):
        self.master_container = master_container

    def Update (self, mouse_x, mouse_y, mouse_click):
        self.mouse_x = mouse_x
        self.mouse_y = mouse_y
        self.mouse_click = mouse_click
        self.mouse_over = False

        # Is mouse over draw deck?
        if ((mouse_x > self.x) and (mouse_y > self.y) and
               (mouse_x < self.rightx) and (mouse_y < self.bottomy)):
            self.mouse_over = True
            # Draw sparkles
            s = self.master_container [23]
            s(self.x, self.rightx, self.y, self.bottomy)
            # Mouse is over draw deck
            # Ignore anything that is not a mouse left click
            if mouse_click:
                self.PrintData ()
                self.clicked_on_deck = True

        self.master_container[22].blit (self.image, self.rect)

# This is the treasure Discard deck object

class TreasureDiscardDeck (pygame.sprite.Sprite):
    def __init__ (self):
        pygame.sprite.Sprite.__init__(self)

        self.deck = []
        self.image = pygame.image.load (os.path.join
            ('data/images/Cards/', 'TreasureCard.png')).convert_alpha()
        self.image = pygame.transform.scale (self.image, (180, 144))
        self.rect = self.image.get_rect()
        self.mouse_x = 0
        self.mouse_y = 0
        self.mouse_over = False
        self.mouse_click = False
        self.x = 1030
        self.rightx = 1210
        self.y = 474
        self.bottomy = 618
        self.rect.topleft = (self.x, self.y)
        self.master_container = None
        self.clicked_on_deck = False # This tells the main loop if the user has clicked on the deck

    def AddCard (self, card):
        self.deck.append(card) # Add a card to the deck.
        card.SetLocation (3)   # Update the location of the card.
        card.player = 0
        card.x = 0
        card.y = 0

    def DrawCard (self):
        # Remove a card from the deck and send it to calling function
        # Is there any cards left to draw?
        x = self.GetLength ()
        if x > 0:
            self.temp = self.deck.pop ()
            return self.temp
        else:
            return None

    def GetLength (self):
        self.length = len(self.deck) - 1
        return self.length

    def PrintData (self):
        print '''\n
Treasure Discard Deck
Cards Remaining: %d
\n''' % len(self.deck)
        
    def SetupMasterContainer (self, master_container):
        self.master_container = master_container

    def Update (self, mouse_x, mouse_y, mouse_click):
        self.mouse_x = mouse_x
        self.mouse_y = mouse_y
        self.mouse_click = mouse_click
        self.mouse_over = False

        # Is mouse over draw deck?
        if ((mouse_x > self.x) and (mouse_y > self.y) and
               (mouse_x < self.rightx) and (mouse_y < self.bottomy)):
            self.mouse_over = True
            # Draw sparkles
            s = self.master_container [23]
            s(self.x, self.rightx, self.y, self.bottomy)
            # Mouse is over draw deck
            # Ignore anything that is not a mouse left click
            if mouse_click:
                self.PrintData ()
                self.clicked_on_deck = True

        self.master_container[22].blit (self.image, self.rect)


